/**
 * Copyright (c) 2017-2024 Nop Platform. All rights reserved.
 * Author: canonical_entropy@163.com
 * Blog:   https://www.zhihu.com/people/canonical-entropy
 * Gitee:  https://gitee.com/canonical-entropy/nop-entropy
 * Github: https://github.com/entropy-cloud/nop-entropy
 */
package com.gitee.wsl.text

import com.gitee.wsl.transform.escape.sample.XmlEscape


class CDataText(val text: String="")  {
    //val text: String = text ?: ""

    override fun toString(): String {
        return text
    }

    override fun hashCode(): Int {
        return text.hashCode()
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true

        if (other !is CDataText) return false

        return text == other.text
    }

    companion object {
        fun encodeIfNecessary(value: Any): Any {
            if (value is String) {
                val str = value.toString()
                if (XmlEscape.valueNeedEscape(str)) return CDataText(str)
            }
            return value
        }
    }
}